<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/index.css">
    <script src="js/vue.min.js"></script>
    <script src="js/element.js"></script>
    <style>
        body, html {
            height: 100%;
            margin: 0;
            overflow-x: hidden;
        }

        .background {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            z-index: -1;
            background-image: url('img/bg.jpg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }

        #box {
            width: 500px;
            height: 620px;
            background: white;
            border-radius: 5px;
            margin: 100px auto;
        }

    </style>
    <link rel="stylesheet" href="css/element.css">
</head>
<body>
<!--背景图-->
<div class="background"></div>
<div id="box">
    <div class="">
        <h1 style="padding-top: 50px;text-align: center">协同会议平台</h1>
        <p style="text-align: center"> 请输入您的信息：</p>
    </div>

<!--    表单-->
    <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="30px" class="demo-ruleForm" style="width: 445px;">

        <el-form-item prop="username">
        <el-input type="text" v-model="ruleForm.username" autocomplete="off" placeholder="用户名"></el-input>

    </el-form-item>

        <el-form-item prop="pass">
            <el-input type="password" v-model="ruleForm.pass" autocomplete="off" placeholder="密码"></el-input>
        </el-form-item>

        <el-form-item  prop="Code" style="width: 245px;display: inline-block">
            <el-input v-model.number="ruleForm.Code" placeholder="验证码"></el-input>
        </el-form-item>
        <span style="margin-left: 15px;" disabled="disabled">加载失败</span>

            <el-form-item  prop="resource">
                <el-radio-group v-model="ruleForm.resource">
                    <el-checkbox label="记住我"></el-checkbox>
                </el-radio-group>
            </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm(ruleForm)" style="width: 420px;">登录</el-button>
        </el-form-item>

        <el-form-item>
            <el-col :span="12">
                <el-link href="forget.html" type="primary">忘记密码?</el-link>
            </el-col>
            <el-col :span="12" style="text-align:right;">
                <el-link href="register.html" type="primary">没有账号?</el-link>
            </el-col>
        </el-form-item>

    </el-form>
<!--    表单-->
</div>
<script>
    new Vue({
        el:"#box",
        data() {
            // 用户名
            var validateUserName = (rule, value, callback) => {
                var pattern = /^[\u3220-\uFA29]+$/
                if (value === '') {
                    callback(new Error('请输入用户名'));
                } else {
                    if (pattern.test(value)) {
                        this.$refs.ruleForm.validateField('');
                        callback();
                    }else {
                        callback(new Error('用户名格式错误，请输入中文字符（字数不限）'));
                    }
                }
            };


            // 密码
            var validatePass = (rule, value, callback) => {
                var pattern = /^\d{6,}$/
                if (value === '') {
                    callback(new Error('请输入密码'));
                } else {
                    if (pattern.test(value) ) {
                        this.$refs.ruleForm.validateField('');
                        callback();
                    }else {
                        callback(new Error('密码格式错误，请输六位及以上数字'));
                    }
                }
            };
            return {
                ruleForm: {
                    username:"",
                    pass: '',
                },
                rules: {
                    username:[
                        { validator: validateUserName, trigger: 'blur' }
                    ],
                    pass: [
                        { validator: validatePass, trigger: 'blur' }
                    ]
                }
            };
        },
        methods:{
            submitForm() {
                this.$refs.ruleForm.validate((valid) => {
                    if (valid) {
                        alert('登录成功！');
                        document.location.href = "home.html"
                    } else {
                        console.log('登录失败');
                return false;
            }
            });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
        }
    })
</script>

</body>
</html>